<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Ubuntu 本地镜像源使用指南</title>
    <style>
        body { 
            font-family: Arial, sans-serif; 
            line-height: 1.6; 
            max-width: 800px; 
            margin: 20px auto; 
            padding: 0 20px; 
        }

        h1, h2 { 
            color: #2c3e50; 
        }

        code { 
            padding: 2px 5px; 
            border-radius: 3px; 
        }

        pre { 
            background: #333; 
            color: #fff; 
            padding: 15px; 
            overflow-x: auto; 
            position: relative;
            margin: 15px 0;
        }

        .note { 
            background: #e3f2fd; 
            padding: 10px; 
            border-left: 4px solid #2196f3; 
        }

        .copy-btn {
            position: absolute;
            top: 5px;
            right: 5px;
            background: #4CAF50;
            color: white;
            border: none;
            padding: 5px 10px;
            border-radius: 3px;
            cursor: pointer;
            opacity: 0.8;
        }

        .copy-btn:hover { 
            opacity: 1; 
        }

        .toast {
            position: fixed;
            bottom: 10%;
            left: 50%;
            transform: translateX(-50%);
            background: #4CAF50;
            color: white;
            padding: 10px 20px;
            border-radius: 5px;
            display: none;
            z-index: 9999;
            pointer-events: none; 
        }

    </style>
</head>
<body>
    <h1>Ubuntu 本地镜像源使用指南</h1>

    <!-- 复制成功提示 -->
    <div class="toast" id="toast">已复制到剪贴板！</div>

    <h2>1. 镜像源地址</h2>
    <ul>
        <li><strong>Ubuntu</strong>: <code>http://[服务器IP]/ubuntu/</code></li>
    </ul>
    <div class="note">
        <p>⚠️ 注意：将 <code>[服务器IP]</code> 替换为实际服务器 IP 或域名。</p>
    </div>

    <h2>2. 客户端配置步骤</h2>
    <h3>步骤 1：备份原有源列表</h3>
    <h4>Ubuntu 22.04 (jammy) 配置示例：</h4>
    <pre><code class="language-bash" id="code1">sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak</code>
<button class="copy-btn" onclick="copyToClipboard('code1')">复制</button></pre>

    <h4>Ubuntu 24.04 (noble) 配置示例：</h4>
    <pre><code class="language-bash" id="code2">sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak</code>
<button class="copy-btn" onclick="copyToClipboard('code2')">复制</button></pre>

    <h3>步骤 2：编辑源列表文件</h3>
    <p>⚠️ 注意：删除原有内容，替换为以下配置（根据您的 Ubuntu 版本选择）：</p>

    <h4>Ubuntu 22.04 (jammy) 配置示例：</h4>
    <pre><code class="language-bash" id="code3">sudo vi /etc/apt/sources.list</code>
<button class="copy-btn" onclick="copyToClipboard('code3')">复制</button></pre>

    <pre><code class="language-bash" id="code4"># 本地镜像源
deb http://[服务器IP]/ubuntu/ jammy main restricted universe multiverse
deb http://[服务器IP]/ubuntu/ jammy-updates main restricted universe multiverse
deb http://[服务器IP]/ubuntu/ jammy-backports main restricted universe multiverse
deb http://[服务器IP]/ubuntu/ jammy-security main restricted universe multiverse</code>
<button class="copy-btn" onclick="copyToClipboard('code4')">复制</button></pre>

    <h4>Ubuntu 24.04 (noble) 配置示例：</h4>
    <pre><code class="language-bash" id="code5">sudo vi /etc/apt/sources.list.d/ubuntu.sources</code>
<button class="copy-btn" onclick="copyToClipboard('code5')">复制</button></pre>
    <pre><code id="code6"># 本地镜像源
Types: deb
URIs: https://[服务器IP]/ubuntu/
Suites: noble noble-updates noble-backports noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg</code>
<button class="copy-btn" onclick="copyToClipboard('code6')">复制</button></pre>

    <h3>步骤 3：更新 APT 缓存</h3>
    <pre><code class="language-bash" id="code7">sudo apt update</code>
<button class="copy-btn" onclick="copyToClipboard('code7')">复制</button></pre>

    <h2>3. 验证配置</h2>
    <p>执行安装测试（例如安装 vim）：</p>
    <pre><code class="language-bash" id="code8">sudo apt install vim</code>
<button class="copy-btn" onclick="copyToClipboard('code8')">复制</button></pre>

    <p>观察下载地址是否来自本地服务器：</p>
    <pre><code>命中:1 http://[服务器IP]/ubuntu jammy InRelease
...</code></pre>

    <h2>4. 故障排查</h2>
    <ul>
        <li><strong>无法连接本地服务器</strong>：检查防火墙是否开放 80 端口</li>
        <li><strong>apt update 报错</strong>：检查 <code>/etc/apt/sources.list</code> 格式是否正确</li>
        <li><strong>无速度提升</strong>：确认客户端与镜像服务器在同一网络</li>
    </ul>

    <div class="note">
        <p>📞 技术支持：联系运维团队</a></p>
    </div>

    <script>
        // 复制功能函数
        function copyToClipboard(elementId) {
            const code = document.getElementById(elementId);
            const textArea = document.createElement('textarea');
            textArea.value = code.textContent;
            document.body.appendChild(textArea);
            textArea.select();
            
            try {
                document.execCommand('copy');
                showToast('已复制到剪贴板！');
            } catch (err) {
                showToast('复制失败，请手动选择复制');
            }
            document.body.removeChild(textArea);
        }

        // 显示提示信息
        function showToast(message) {
            const toast = document.getElementById('toast');
            toast.textContent = message;
            toast.style.display = 'block';
            setTimeout(() => {
                toast.style.display = 'none';
            }, 2000);
        }
    </script>

</body>
</html>